import oss2
from oss2.credentials import EnvironmentVariableCredentialsProvider


from oss2.models import PutObjectResult

from ...init import ENV




# 从环境变量中获取访问凭证
auth: oss2.ProviderAuthV4 = oss2.ProviderAuthV4(
    EnvironmentVariableCredentialsProvider()
)


bucket: oss2.Bucket = oss2.Bucket(auth, ENV.ENDPOINT, ENV.BUCKETNAME, region=ENV.REGION)


class AliOssUtils:
    @staticmethod
    def uploadFile(object_name: str, data: bytes) -> PutObjectResult:
        return bucket.put_object(object_name, data)
